package com.anysoft.register;

import android.content.Context;
import android.content.Intent;
import android.inputmethodservice.KeyboardView;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.text.Editable;
import android.text.InputFilter;
import android.text.InputType;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.style.ClickableSpan;
import android.view.ActionMode;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.anysoft.MentorConst;
import com.anysoft.utils.MentorLogger;
import com.blankj.utilcode.util.ToastUtils;
import com.anysoft.HostConstant;
import com.anysoft.R;
import com.anysoft.base.BaseActivity;
import com.anysoft.bean.BaseBean;
import com.anysoft.bean.QueryBankInfoListBean;
import com.anysoft.bean.QueryBankTypeBean;
import com.anysoft.bean.QueryCertificateTypeBean;
import com.anysoft.bean.QuickAuthApplyBean;
import com.anysoft.bean.SelectWarmPromptByTypeBean;
import com.anysoft.bean.SmartCardBinByBankAccountNoBean;
import com.anysoft.event.RegisterEvent;
import com.anysoft.event.RegisterSuccessEvent;
import com.anysoft.linstener.OnNextLinstener;
import com.anysoft.me.callback.StringDialogCallback;
import com.anysoft.me.config.ServiceConfig;
import com.anysoft.me.utils.PermissionManager;
import com.anysoft.utils.ActivityUtils;
import com.anysoft.utils.AnalyticsEventUtils;
import com.anysoft.utils.ChinaPayUtils;
import com.anysoft.utils.CommonUtil;
import com.anysoft.utils.HttpUtils;
import com.anysoft.utils.IcbcClickableSpan;
import com.anysoft.utils.StringUtils;
import com.anysoft.view.CustomMarqueeTextView;
import com.anysoft.view.IcbcKeyboardUtil;
import com.anysoft.view.IcbcKeyboardUtilNew;
import com.anysoft.view.picker.NomarlPickerPopupWindow;
import com.anysoft.web.MerChantsBankActivity;
import com.anysoft.web.SelectWarmPromptByTypeActivity;
import com.google.gson.Gson;
import com.hxcr.chinapay.activity.Initialize;
import com.hxcr.chinapay.util.CPGlobaInfo;
import com.hxcr.chinapay.util.Utils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

import static com.anysoft.HostConstant.START_CHANTS_BANK;
import static com.anysoft.MentorConst.FIRST_CUSTOMER;
import static com.anysoft.R.id.tv_register_step_1_user_type;

/**
 * Created by wwq on 2017/1/17.
 * 注册页面
 */

public class RegisterStep1_2Activity extends BaseActivity implements IcbcKeyboardUtil.onWhichKeyClickListener, PermissionManager.OnPermissionListener {


    @BindView(R.id.leftButton)
    Button leftButton;
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.rightButton)
    Button rightButton;
    @BindView(R.id.titlebar)
    FrameLayout titlebar;
    @BindView(R.id.iv_register_step_1)
    ImageView ivRegisterStep1;
    @BindView(R.id.tv_register_step_1)
    TextView tvRegisterStep1;
    @BindView(R.id.iv_register_step_2)
    ImageView ivRegisterStep2;
    @BindView(R.id.tv_register_step_2)
    TextView tvRegisterStep2;
    @BindView(R.id.iv_register_step_3)
    ImageView ivRegisterStep3;
    @BindView(R.id.tv_register_step_3)
    TextView tvRegisterStep3;
    @BindView(R.id.et_register_step_1_user_name)
    EditText etRegisterStep1UserName;
    @BindView(tv_register_step_1_user_type)
    TextView tvRegisterStep1UserType;
    @BindView(R.id.et_register_step_1_user_id)
    EditText etRegisterStep1UserId;
    @BindView(R.id.iv_register_step_1_bank_ocr)
    ImageView iv_register_step_1_bank_ocr;
    @BindView(R.id.cb_register_step_1)
    CheckBox cbRegisterStep1;
    @BindView(R.id.ll_register_step_1_1)
    LinearLayout llRegisterStep11;
    @BindView(R.id.et_register_step_1_bank_number)
    EditText etRegisterStep1BankNumber;
    @BindView(R.id.tv_register_step_1_bank_name_title)
    TextView tvRegisterStep1BankNameTitle;
    @BindView(R.id.iv_register_step_1_bank_name)
    ImageView ivRegisterStep1BankName;
    @BindView(R.id.tv_register_step_1_bank_name)
    TextView tvRegisterStep1BankName;
    @BindView(R.id.et_register_step_1_phone_number)
    EditText etRegisterStep1PhoneNumber;
    @BindView(R.id.tv_register_step_1_verification_code_title)
    TextView tvRegisterStep1VerificationCodeTitle;
    @BindView(R.id.tv_register_step_1_verification_code)
    TextView tvRegisterStep1VerificationCode;
    @BindView(R.id.et_register_step_1_verification_code)
    EditText etRegisterStep1VerificationCode;
    @BindView(R.id.tv_register_step_1_tip)
    TextView tvRegisterStep1Tip;
    @BindView(R.id.ll_register_step_1_2)
    LinearLayout llRegisterStep12;
    @BindView(R.id.btn_register_step_1)
    Button btnRegisterStep1;
    /**
     * 倒计时
     */
    private static final int COUNT_DOWN = 99;
    /**
     * 倒计时秒数
     */
    private static final int COUNT_DOWN_NUMBER = 120;
    @BindView(R.id.rl_register_step_1_bank_name)
    RelativeLayout rlRegisterStep1BankName;
    @BindView(R.id.rootview)
    LinearLayout rootview;
    @BindView(R.id.tv_register_step_1_tips)
    TextView tvRegisterStep1Tips;
    @BindView(R.id.iv_leftButton)
    ImageView ivLeftButton;
    @BindView(R.id.cmtv_title)
    CustomMarqueeTextView cmtvTitle;
    @BindView(R.id.cb_register_step_1_promise)
    CheckBox cbRegisterStep1Promise;
    @BindView(R.id.ll_register_step_1_promise)
    LinearLayout llRegisterStep1Promise;
    @BindView(R.id.keyboard_view)
    KeyboardView keyboardView;

    private NomarlPickerPopupWindow nomarlPickerPopupWindow;
    private int currentPosition;
    private int selectPosition = -1;
    List<QueryCertificateTypeBean.DataBean> idTypeList = new ArrayList<>();
    List<QueryBankInfoListBean.DataBean> bankList = new ArrayList<>();
    ArrayList<String> list = new ArrayList<>();
    private boolean idPopShow = false;
    private boolean isScanBankResult = false;
//    private IcbcKeyboardUtil keyboardUtil;

    private String merId = "";
    private String currentCapitalMode = "";
    //是否是一类账户
    private boolean isFirstCus = false;

    private boolean isFirstComing = true;

    private IcbcKeyboardUtilNew icbcKeyboardUtilNew;
    private String id_name, id_number, cardNum, bankName, id_address, id_time;
    private String toTarget;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_register_step1_2);
        ButterKnife.bind(this);

        getIntentValue();

        tvRegisterStep1VerificationCode.setClickable(false);
        etRegisterStep1UserId.setFilters(new InputFilter[]{new InputFilter.LengthFilter(18)}); //最大输入长度

        //第二步输入银行预留手机号码
        etRegisterStep1PhoneNumber.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                if (time <= 0) {
                    if (s.toString().length() < 11) {
                        tvRegisterStep1VerificationCode.setClickable(false);
                        tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_gray);
                    } else {
                        tvRegisterStep1VerificationCode.setClickable(true);
                        tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_red);
                    }
                }
            }

            @Override
            public void afterTextChanged(Editable s) {

            }
        });

        //第二步输入银行卡号
        etRegisterStep1BankNumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    isScanBankResult = false;
                } else {
                    if (llRegisterStep12.isShown() && !TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                        queryBankType();
                        queryCardBinByBankAccountNo();
                    }
                }
            }
        });

        //第二步银行预留手机号码
        etRegisterStep1PhoneNumber.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    if (llRegisterStep12.isShown() && !TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                        queryBankType();
                        queryCardBinByBankAccountNo();
                    }
                } else {
                }
            }
        });

        //第二步输入验证码
        etRegisterStep1VerificationCode.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                } else {
                    if (llRegisterStep12.isShown() && !TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                        queryBankType();
                    }
                }
            }
        });

        title.setText("开户");


        // 禁止弹出系统默认的软键盘
        if (Build.VERSION.SDK_INT <= 10) {
            etRegisterStep1UserId.setInputType(InputType.TYPE_NULL);
        } else {
            this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
            try {
                Class<EditText> cls = EditText.class;
                Method setSoftInputShownOnFocus;
                setSoftInputShownOnFocus = cls.getMethod("setShowSoftInputOnFocus", boolean.class);
                setSoftInputShownOnFocus.setAccessible(true);
                setSoftInputShownOnFocus.invoke(etRegisterStep1UserId, false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        // 禁止长按选择
        etRegisterStep1UserId.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            @Override
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                // 这里可以添加自己的菜单选项（前提是要返回true的）
                return false;// 返回false 就是屏蔽ActionMode菜单
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
        // 设置监听动作，弹出自定义键盘
        etRegisterStep1UserId.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (!TextUtils.isEmpty(identityType)) {
                    if ("0".equals(identityType)) {
                        etRegisterStep1UserId.setFilters(new InputFilter[]{new InputFilter.LengthFilter(18)}); //最大输入长度
                        collapseSoftInputMethod(etRegisterStep1UserId.getWindowToken());
                        if (icbcKeyboardUtilNew == null) {
                            icbcKeyboardUtilNew = new IcbcKeyboardUtilNew(mActivity, mActivity, etRegisterStep1UserId);
                            icbcKeyboardUtilNew.showNumber();
                        } else {
                            icbcKeyboardUtilNew.showKeyboard();
                        }
                        return false;
                    } else {
                        etRegisterStep1UserId.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)}); //最大输入长度
                        openInputMethod(etRegisterStep1UserId);
                        if (icbcKeyboardUtilNew != null && icbcKeyboardUtilNew.isShowing()) {
                            icbcKeyboardUtilNew.hideKeyboard();
                        }
                        return false;
                    }
                } else {
                    return false;
                }
            }
        });

        etRegisterStep1UserId.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (!TextUtils.isEmpty(identityType)) {
                    if ("0".equals(identityType)) {
                        etRegisterStep1UserId.setFilters(new InputFilter[]{new InputFilter.LengthFilter(18)}); //最大输入长度
                        collapseSoftInputMethod(etRegisterStep1UserId.getWindowToken());
                        if (hasFocus) {
                            if (icbcKeyboardUtilNew != null) {
                                if (!icbcKeyboardUtilNew.isShowing()) {
                                    icbcKeyboardUtilNew.showKeyboard();
                                }
                            } else {
                                icbcKeyboardUtilNew = new IcbcKeyboardUtilNew(mActivity, mActivity, etRegisterStep1UserId);
                                icbcKeyboardUtilNew.showNumber();
                            }
                        } else {
                            if (icbcKeyboardUtilNew != null && icbcKeyboardUtilNew.isShowing()) {
                                icbcKeyboardUtilNew.hideKeyboard();
                            }
                        }
                    } else {
                        etRegisterStep1UserId.setFilters(new InputFilter[]{new InputFilter.LengthFilter(50)}); //最大输入长度
                    }
                }
            }
        });

        etRegisterStep1UserName.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                etRegisterStep1UserName.setCursorVisible(true);
                return false;
            }
        });

        setOnNextLinstener(new OnNextLinstener() {
            @Override
            public void OnCancelNext() {
                if (isScanBankResult) {
                    quickAuthApply();
                    isScanBankResult = false;
                }
            }

            @Override
            public void OnConfirmNext() {
            }

            @Override
            public void OndoConfirm() {

            }
        });
        tvRegisterStep1UserType.setText("身份证");
        initTips();
        // TODO: 2017/11/21 开户限制只有身份证开户
//        getIdType();
        getBankList();
    }

    private void getIntentValue() {
        Intent intent = getIntent();
        id_name = intent.getStringExtra("id_name");
        id_number = intent.getStringExtra("id_number");
        id_address = intent.getStringExtra("address");
        id_time = intent.getStringExtra("id_time");
        toTarget = intent.getStringExtra("toTarget");
        if ("toBank".equals(toTarget) && !TextUtils.isEmpty(id_name) && !TextUtils.isEmpty(id_number)) {
            setRegisterViewState();
        } else {
            llRegisterStep11.setVisibility(View.VISIBLE);
            llRegisterStep12.setVisibility(View.GONE);
        }
        etRegisterStep1UserName.setText(id_name);
        etRegisterStep1UserId.setText(id_number);
    }

    @Override
    protected void onPause() {
        super.onPause();
    }

    public void openInputMethod(final EditText editText) {

        Timer timer = new Timer();
        timer.schedule(new TimerTask() {
            public void run() {
                InputMethodManager inputManager = (InputMethodManager) editText
                        .getContext().getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                inputManager.showSoftInput(editText, 0);
            }
        }, 200);
    }

    @Override
    public void keyDown(int keyCode) {

    }

    /**
     * 初始化提示协议
     */
    private void initTips() {
        String tip1 = "《电子交易服务协议》";
        String tip2 = "《证券投资基金投资人权益须知》";
        String tip3 = "《基金直销货币基金快速赎回业务协议》";
        SpannableString spantip1 = new SpannableString(tip1);
        SpannableString spantip2 = new SpannableString(tip2);
        SpannableString spantip3 = new SpannableString(tip3);
        ClickableSpan clicktip1 = new IcbcClickableSpan(tip1, this, 1);
        ClickableSpan clicktip2 = new IcbcClickableSpan(tip2, this, 2);
        ClickableSpan clicktip3 = new IcbcClickableSpan(tip3, this, 3);
        spantip1.setSpan(clicktip1, 0, tip1.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spantip2.setSpan(clicktip2, 0, tip2.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        spantip3.setSpan(clicktip3, 0, tip3.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
        tvRegisterStep1Tips.setText("请阅读并同意以下协议");
        tvRegisterStep1Tips.append(spantip1);
        tvRegisterStep1Tips.append(spantip2);
        tvRegisterStep1Tips.append(spantip3);
        tvRegisterStep1Tips.setMovementMethod(LinkMovementMethod.getInstance());

        tvRegisterStep1Tips.setLongClickable(false);
        tvRegisterStep1Tips.setHighlightColor(getResources().getColor(android.R.color.transparent));
    }


    /**
     * 查询银行卡bin信息
     */
    public void queryBankType() {
        Map<String, String> params = new HashMap<>();
        params.put("bankNumber", etRegisterStep1BankNumber.getText().toString());
        OkGo.<String>post(HostConstant.QUERY_BANK_TYPE)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        MentorLogger.LogJson(TAG + "查询银行卡是否为1类账户(允许开户)URL:", response.body());
                        UpdateQueryBankType(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }


    public void UpdateQueryBankType(String json) {

        QueryBankTypeBean bean;
        try {
            bean = new Gson().fromJson(json, QueryBankTypeBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null || TextUtils.isEmpty(bean.getData().getOneAccount())) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        if ("false".equals(bean.getData().getOneAccount())) {
            showConfirmAlert(mActivity, FIRST_CUSTOMER);
            isFirstCus = false;
        } else {
            isFirstCus = true;
        }
    }

    /**
     * 获取证件类型
     */
    // TODO: 2017/11/21 开户限制只有身份证开户
    private void getIdType() {
        OkGo.<String>post(HostConstant.QUERY_CERTIFICATE_TYPE)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, null))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateIdType(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateIdType(String json) {
        idTypeList.clear();
        list.clear();

        QueryCertificateTypeBean bean;
        try {
            bean = new Gson().fromJson(json, QueryCertificateTypeBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }
        idTypeList.addAll(bean.getData());
        initPopList(1);

        if (isFirstComing) {
            isFirstComing = false;
            identityType = idTypeList.get(0).getTypeValue();
            tvRegisterStep1UserType.setText(idTypeList.get(0).getTypeName().length() > 4 ?
                    idTypeList.get(0).getTypeName().substring(0, 4) :
                    idTypeList.get(0).getTypeName());
        }
        if (idPopShow) {
            showPicker();
        }
    }

    /**
     * 获取银行卡列表
     */
    private void getBankList() {
        Map<String, String> params = new HashMap<>();
        params.put("OpenAccountState", "1");
        OkGo.<String>post(HostConstant.QUERY_BANK_INFO_LIST)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateBankList(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    private void UpdateBankList(String json) {
        bankList.clear();

        QueryBankInfoListBean bean;
        try {
            bean = new Gson().fromJson(json, QueryBankInfoListBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null ||
                bean.getData().isEmpty() || bean.getData().size() < 1) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        bankList.addAll(bean.getData());
        initPopList(2);

        if (idPopShow) {
            showPicker();
        }
    }

    private void showPicker() {

        nomarlPickerPopupWindow = new NomarlPickerPopupWindow(mActivity, itemsOnClick, list);
        nomarlPickerPopupWindow.showAtLocation(findViewById(R.id.rootview),
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);

        if (llRegisterStep11.isShown()) {
            // TODO: 2017/11/21 开户只有身份证开户
//            nomarlPickerPopupWindow.setTitle_str("请选择您的证件");
        } else {
            nomarlPickerPopupWindow.setTitle_str("请选择您的银行");
        }

        nomarlPickerPopupWindow.setOnPickerChangeListener(
                new NomarlPickerPopupWindow.OnPickerChangeListener() {
                    @Override
                    public void onPickerChange(int position) {
                        currentPosition = position;
                    }
                });

    }

    //为弹出窗口实现监听类
    private View.OnClickListener itemsOnClick = new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            nomarlPickerPopupWindow.dismiss();
            switch (v.getId()) {
                case R.id.btn_cancel:
                    if (nomarlPickerPopupWindow != null) {
                        nomarlPickerPopupWindow.dismiss();
                    }
                    break;
                case R.id.btn_sure:
                    if (nomarlPickerPopupWindow != null) {
                        selectPosition = currentPosition;
                        nomarlPickerPopupWindow.dismiss();
                        if (llRegisterStep11.isShown()) {
                            // TODO: 2017/11/21 开户限制只有身份证开户
//                            tvRegisterStep1UserType.setText(idTypeList.get(selectPosition).getTypeName().length() > 4 ?
//                                    idTypeList.get(selectPosition).getTypeName().substring(0, 4) :
//                                    idTypeList.get(selectPosition).getTypeName());
//                            identityType = idTypeList.get(selectPosition).getTypeValue();
//                            if ("4".equals(identityType) || "A".equals(identityType) || "6".equals(identityType)) {
//                                llRegisterStep1Promise.setVisibility(View.VISIBLE);
//                            } else {
//                                llRegisterStep1Promise.setVisibility(View.GONE);
//                                cbRegisterStep1Promise.setChecked(false);
//                            }
                        } else {
                            bankName = bankList.get(selectPosition).getBankName();
                            tvRegisterStep1BankName.setText(bankName);
                            bankCode = bankList.get(selectPosition).getBankCode();
                            trustChannelId = bankList.get(selectPosition).getTrustChannelId();
                            currentCapitalMode = bankList.get(selectPosition).getCapitalMode();
                            isScanBankResult = false;
                        }
                    }
                    break;
                default:
                    break;
            }
        }
    };

    @OnClick({R.id.leftButton, tv_register_step_1_user_type,
            R.id.rl_register_step_1_bank_name, R.id.tv_register_step_1_verification_code,
            R.id.tv_register_step_1_tip, R.id.btn_register_step_1, R.id.iv_register_step_1_bank_ocr})
    public void onClick(View view) {
        if (!isFastDoubleClick()) {

            collapseSoftInputMethod(view.getWindowToken());
            if (icbcKeyboardUtilNew != null && icbcKeyboardUtilNew.isShowing()) {
                icbcKeyboardUtilNew.hideKeyboard();
            }
            if (llRegisterStep12.isShown() && etRegisterStep1BankNumber.hasFocus() && !TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                queryBankType();
                queryCardBinByBankAccountNo();
            }
//            if (keyboardUtil.isShowing()) {
//                keyboardUtil.hideKeyboard();
//            }
            switch (view.getId()) {
                case R.id.iv_register_step_1_bank_ocr://银行卡ocr扫描
                    requestIdentityPermissions();
                    break;
                case R.id.leftButton:
                    if ("toIdCard".equals(toTarget) && llRegisterStep12.isShown()) {
                        llRegisterStep11.setVisibility(View.VISIBLE);
                        llRegisterStep12.setVisibility(View.GONE);
                        selectPosition = -1;

                        initPopList(1);
                    } else {
                        finish();
                    }
                    break;

                // TODO: 2017/11/21 开户限制只有身份证开户
//                case R.id.tv_register_step_1_user_type:
//                    idPopShow = true;
//                    currentPosition = 0;
//                    initPopList(1);//1.证件类型 2.银行卡列表
//                    if (list != null && !list.isEmpty() && list.size() > 0) {
//                        showPicker();
//                    } else {
//                        getIdType();
//                    }
//                    break;
                case R.id.rl_register_step_1_bank_name: //所属银行
                    idPopShow = true;
                    currentPosition = 0;

                    initPopList(2);//1.证件类型 2.银行卡列表
                    if (list != null && !list.isEmpty() && list.size() > 0) {
                        showPicker();
                    } else {
                        getBankList();
                    }
                    break;
                case R.id.tv_register_step_1_verification_code:

                    if (TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                        showConfirmAlert(mActivity, "请输入银行卡号");
                        return;
                    }
                    if (!isFirstCus) {
                        showConfirmAlert(mActivity, FIRST_CUSTOMER);
                        return;
                    }
                    if (TextUtils.isEmpty(bankCode)) {
                        showConfirmAlert(mActivity, "请选择所属银行");
                        return;
                    }
                    if (TextUtils.isEmpty(etRegisterStep1PhoneNumber.getText().toString())) {
                        showConfirmAlert(mActivity, "请输入银行预留手机号");
                        return;
                    }
                    if (isScanBankResult) {
                        showConfirmAlert(this, "提示", "请核对扫描结果, 如有误请手动输入。\n\n银行卡名称: " + bankName + "\n银行卡号: " + cardNum,
                                "有误,去修改", "无误,继续");
                    } else {
                        quickAuthApply();
                    }
                    break;
                case R.id.tv_register_step_1_tip:
                    selectWarmPromptByType("2", "交易提醒及温馨提示");
                    break;
                case R.id.btn_register_step_1:
                    if (llRegisterStep11.isShown()) {
                        if (TextUtils.isEmpty(etRegisterStep1UserName.getText().toString().trim())) {
                            showConfirmAlert(mActivity, "请输入真实姓名");
                            return;
                        }
                        // TODO: 2017/11/21 开户限制只有身份证开户
//                        if (TextUtils.isEmpty(identityType)) {
//                            showConfirmAlert(mActivity, "请选择证件类型");
//                            return;
//                        }
                        if (TextUtils.isEmpty(etRegisterStep1UserId.getText().toString())) {
                            showConfirmAlert(mActivity, "请输入证件号码");
                            return;
                        }
                        if ("0".equals(identityType) && !StringUtils.isIdentity(etRegisterStep1UserId.getText()
                                .toString())) {
                            showConfirmAlert(mActivity, "请输入合规身份证号");
                            return;
                        }
                        if (llRegisterStep1Promise.isShown() && !cbRegisterStep1Promise.isChecked()) {
                            showConfirmAlert(mActivity, "请勾选”本人承诺已在国内居住满一年以上，并对此承担法律责任。”");
                            return;
                        }
                        if (!cbRegisterStep1.isChecked()) {
                            showConfirmAlert(mActivity, "请阅读并同意协议");
                            return;
                        }
                        setRegisterViewState();
                        AnalyticsEventUtils.toFillRealNameEvent(this);
                    } else {
                        AnalyticsEventUtils.toFillBankAccountEvent(this);
                        if (TextUtils.isEmpty(etRegisterStep1BankNumber.getText().toString())) {
                            showConfirmAlert(mActivity, "请输入银行卡号");
                            return;
                        }
                        if (!isFirstCus) {
                            showConfirmAlert(mActivity, FIRST_CUSTOMER);
                            return;
                        }
                        if (TextUtils.isEmpty(bankCode)) {
                            showConfirmAlert(mActivity, "请选择所属银行");
                            return;
                        }
                        if (TextUtils.isEmpty(etRegisterStep1PhoneNumber.getText().toString())) {
                            showConfirmAlert(mActivity, "请输入银行预留手机号");
                            return;
                        }
                        if (TextUtils.isEmpty(authApplyNo)) {
                            showConfirmAlert(mActivity, "请先获取短信验证码");
                            return;
                        }
                        if (TextUtils.isEmpty(etRegisterStep1VerificationCode.getText().toString())) {
                            showConfirmAlert(mActivity, "请输入短信验证码");
                            return;
                        }

                        if (!TextUtils.isEmpty(currentDataBean.getMerId())) {
                            //银联渠道
                            UpdateChinaPayAuth(currentDataBean);
                        } else {
                            quickAuthConfirm(authApplyNo);
                        }
                    }
                    break;
            }
        }
    }

    private void requestIdentityPermissions() {
        if (PermissionManager.getInstance().checkPermissions(this, PermissionManager.PERMISSION_READ_WEITE_CAMERA)) {
            ActivityUtils.openBankCardCamera(this);
        } else {
            PermissionManager.getInstance().requestPermissions(this, PermissionManager.REQUEST_READ_WEITE_CAMERA,
                    PermissionManager.PERMISSION_READ_WEITE_CAMERA, this);
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        PermissionManager.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    @Override
    public void onPermissionSuccess() {
        ActivityUtils.openBankCardCamera(this);
    }

    @Override
    public void onPermissionFail() {
        ToastUtils.showShort("请求权限失败,请重试");
    }

    private void setRegisterViewState() {
        llRegisterStep11.setVisibility(View.GONE);
        llRegisterStep12.setVisibility(View.VISIBLE);
        selectPosition = -1;

        initPopList(2);
    }

    private String bankCode;
    private String identityType = "0";
    private String trustChannelId;

    private void quickAuthApply() {
        Map<String, String> params = new HashMap<>();

        if (checkParam(params, "bankCode", bankCode, "请选择所属银行")) {
            return;
        }
        //3.0.8增加字段
        if (checkParam(params, "bankName", bankName, "请选择所属银行")) {
            return;
        }
        if (checkParam(params, "bankAccountNo", etRegisterStep1BankNumber.getText().toString(), "请输入银行卡号")) {
            return;
        }
        if (checkParam(params, "username", etRegisterStep1UserName.getText().toString().trim(), "请输入真实姓名")) {
            return;
        }
        if (checkParam(params, "identityType", identityType, "请选择证件类型")) {
            return;
        }
        if (checkParam(params, "identityNo", etRegisterStep1UserId.getText().toString().trim(), "请输入证件号码")) {
            return;
        }
        if (checkParam(params, "mobilePhone", etRegisterStep1PhoneNumber.getText().toString().trim(), "请输入银行预留手机号")) {
            return;
        }
        if (checkParam(params, "authType", "0", "请确认鉴权类型")) {
            return;
        }
        if (checkParam(params, "trustChannelId", trustChannelId, "请确认交易渠道")) {
            return;
        }
        params.put("operationType", "0");//0-开户 1-忘记密码  2-忘记密码
        setVerificationCodeStatuts(false);
        OkGo.<String>post(HostConstant.QUICK_AUTH_APPLY)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        UpdateQuickAuth(1, response.body());
                    }

                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        setVerificationCodeStatuts(true);
                        showToast("网络加载失败，请稍后再试!");
                    }
                });
    }

    private String authApplyNo;
    private RegisterEvent saveRegisterEvent = new RegisterEvent();
    private QuickAuthApplyBean.DataBean currentDataBean;

    private void setVerificationCodeStatuts(boolean isOpen) {
        if (isOpen) {
            if (etRegisterStep1PhoneNumber.getText().toString().length() < 11) {
                tvRegisterStep1VerificationCode.setText("获取验证码");
                tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_gray);
                tvRegisterStep1VerificationCode.setClickable(false);
            } else {
                tvRegisterStep1VerificationCode.setText("获取验证码");
                tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_red);
                tvRegisterStep1VerificationCode.setClickable(true);
            }

        } else {
            tvRegisterStep1VerificationCode.setText("获取验证码");
            tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_gray);
            tvRegisterStep1VerificationCode.setClickable(false);

        }
    }

    /**
     * @param type 1.鉴权申请 2.鉴权确认
     * @param json
     */
    private void UpdateQuickAuth(int type, String json) {
        hideLoading();
        QuickAuthApplyBean bean;
        try {
            bean = new Gson().fromJson(json, QuickAuthApplyBean.class);
        } catch (Exception exception) {
            if (type == 1) {
                setVerificationCodeStatuts(true);
            }
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            if (type == 1) {
                setVerificationCodeStatuts(true);
            }
            return;
        }

        if (bean == null || bean.getData() == null) {
            if (type == 1) {
                setVerificationCodeStatuts(true);
            }
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }
        switch (type) {
            case 1:

                setVerificationCodeStatuts(true);
                runTimerTask();
                currentDataBean = bean.getData();

                authApplyNo = bean.getData().getAuthApplyNo();

                saveRegisterEvent.setBankAccountNo(etRegisterStep1BankNumber.getText().toString().trim());
                saveRegisterEvent.setTrustChannelId(trustChannelId);
                saveRegisterEvent.setUsername(etRegisterStep1UserName.getText().toString().trim());
                saveRegisterEvent.setMobilePhone(etRegisterStep1PhoneNumber.getText().toString().trim());
                saveRegisterEvent.setIdentityType(identityType);
                saveRegisterEvent.setIdentityNo(etRegisterStep1UserId.getText().toString().trim());
                saveRegisterEvent.setBankCode(bankCode);

                break;
            case 2:
                if (!etRegisterStep1BankNumber.getText().toString().equals(saveRegisterEvent.getBankAccountNo()) ||
                        !etRegisterStep1UserName.getText().toString().trim().equals(saveRegisterEvent.getUsername()) ||
                        !etRegisterStep1PhoneNumber.getText().toString().equals(saveRegisterEvent.getMobilePhone()) ||
                        !etRegisterStep1UserId.getText().toString().equals(saveRegisterEvent.getIdentityNo()) ||
                        !identityType.equals(saveRegisterEvent.getIdentityType()) ||
                        !bankCode.equals(saveRegisterEvent.getBankCode())
                        ) {
                    showConfirmAlert(mActivity, "您修改了个人信息，请重新获取验证码");
                    authApplyNo = "";
                    return;
                }

                QuickAuthApplyBean.DataBean authDataBean = bean.getData();
                saveRegisterEvent.setAuthApplyNo(authDataBean.getAuthApplyNo());
                saveRegisterEvent.setAddress(TextUtils.isEmpty(id_address) ? "" : id_address);
                if (!StringUtils.isNullOrEmpty(id_time)) {
                    if (id_time.contains("长期")) {
                        saveRegisterEvent.setCertificateValidEver("1");
                        id_time = "长期有效";
                    }else {
                        saveRegisterEvent.setCertificateValidEver("0");
                    }
                } else {
                    id_time = "";
                    saveRegisterEvent.setCertificateValidEver("0");
                }
                saveRegisterEvent.setIdValidDate(id_time);
                Intent intent = null;
                if ("H5".equals(authDataBean.getAuthMethod())) {
                    intent = new Intent().setClass(mActivity, MerChantsBankActivity.class);
                    intent.putExtra("formContent", authDataBean.getFormContent());
                    intent.putExtra("returnUrl", authDataBean.getReturnUrl());
                    startActivityForResult(intent, START_CHANTS_BANK);
                } else {
                    gotoNextPage();
                }
                break;
            default:
                break;
        }
    }

    private void gotoNextPage() {
        Intent intent = new Intent().setClass(mActivity, RegisterStep2Activity.class);
        intent.putExtra("registerEvent", saveRegisterEvent);
        startActivity(intent);
    }

    /**
     * 银联插件报文获取
     *
     * @param bean
     */
    private void UpdateChinaPayAuth(QuickAuthApplyBean.DataBean bean) {
        Utils.setPackageName(getPackageName());
        String xml = ChinaPayUtils.getXml(ServiceConfig.CHINA_PAY_ENVIRONMENT, bean.getMerId(), bean.getMerOrderId(),
                bean.getMerOrderTime(), bean.getCharacterCode(), bean.getSign());

        // 调用银行插件进行开户，在此类的onResume()方法中获取插件的返回结果
        Intent inten = new Intent(this, Initialize.class);
        inten.putExtra(CPGlobaInfo.XML_TAG, xml);
        startActivity(inten);
    }

    @Override
    protected void onResume() {
        super.onResume();
        if (Utils.getPayResult() != null && !Utils.getPayResult().equals("")) {
            String str = Utils.getPayResult();
            MentorLogger.Log(TAG, "银联返回数据：  " + str);
            String respCode = str.substring(10, 14);
            if (respCode.equals("0000")) {
                quickAuthConfirm(authApplyNo);
            } else {
                showConfirmAlert(mActivity, "银联认证失败");
            }
            ChinaPayUtils.printChinapayResultCodeInfo(respCode);
        }
        CPGlobaInfo.init(); // 清空返回结果
    }

    private void quickAuthConfirm(String authApplyNo) {
        Map<String, String> params = new HashMap<>();

        if (checkParam(params, "authApplyNo", authApplyNo, "请先获取短信验证码")) {
            return;
        }
        if (checkParam(params, "verifyCode", etRegisterStep1VerificationCode.getText().toString(), "请输入短信验证码")) {
            return;
        }
        OkGo.<String>post(HostConstant.QUICK_AUTH_CONFIRM)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringDialogCallback(this) {
                    @Override
                    public void onSuccess(Response<String> response) {
                        MentorLogger.LogJson(TAG + "鉴权确认(开户第一步):", response.body());
                        UpdateQuickAuth(2, response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    /**
     * @param type 1.证件类型 2.银行卡列表
     */
    private void initPopList(int type) {
        list.clear();

        switch (type) {
            case 1:
                for (QueryCertificateTypeBean.DataBean dataBean : idTypeList) {
                    list.add(dataBean.getTypeName());
                }
                break;
            case 2:
                for (QueryBankInfoListBean.DataBean dataBean : bankList) {
                    list.add(dataBean.getBankName());
                }
                break;
            default:
                break;
        }

    }

    @Override
    public void onBackPressed() {
        if (icbcKeyboardUtilNew != null && icbcKeyboardUtilNew.isShowing()) {
            icbcKeyboardUtilNew.hideKeyboard();
        } else {
            if ("toIdCard".equals(toTarget) && llRegisterStep12.isShown()) {
                llRegisterStep11.setVisibility(View.VISIBLE);
                llRegisterStep12.setVisibility(View.GONE);
                selectPosition = -1;

                initPopList(1);
            } else {
                super.onBackPressed();
            }
        }
    }

    private Timer timer;
    private int time = 0;

    /**
     * 验证码重发倒计时
     */
    private void runTimerTask() {
        timer = new Timer();
        time = COUNT_DOWN_NUMBER;
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                Message msg = new Message();
                msg.what = COUNT_DOWN;
                msg.obj = time;
                handler.sendMessage(msg);
                time--;
            }
        };
        timer.schedule(task, 0, 1000);
    }

    private Handler handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case COUNT_DOWN:
                    if ((Integer) msg.obj > 0) {
                        tvRegisterStep1VerificationCode.setText(String.valueOf(msg.obj) + "秒后重发");
                        tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_gray);
                        tvRegisterStep1VerificationCode.setClickable(false);
                    } else {
                        if (timer != null) {
                            timer.cancel();
                        }

                        if (etRegisterStep1PhoneNumber.getText().toString().length() < 11) {
                            tvRegisterStep1VerificationCode.setText("获取验证码");
                            tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_gray);
                            tvRegisterStep1VerificationCode.setClickable(false);
                        } else {
                            tvRegisterStep1VerificationCode.setText("获取验证码");
                            tvRegisterStep1VerificationCode.setBackgroundResource(R.color.bg_btn_red);
                            tvRegisterStep1VerificationCode.setClickable(true);
                        }

                    }
                    break;

                default:
                    break;
            }
        }
    };

    protected void onDestroy() {
        if (timer != null) {
            timer.cancel();
        }
        super.onDestroy();
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onGestureSetCallBack(RegisterSuccessEvent event) {
        if (event.isSuccess) {
            finish();
        }
    }

    public void selectWarmPromptByType(String type, final String title) {
        Map<String, String> params = new HashMap<>();
        params.put("warmPromptType", type);
        OkGo.<String>post(HostConstant.SELECT_WARM_PROMPT_BY_TYPE)
                .tag(this)
                .params(HttpUtils.getCommonParams(this, params))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        MentorLogger.LogJson(TAG + "获取温馨提示URL:", response.body());
                        UpdateSelectWarmPromptByType(response.body(), title);
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                        showToast("网络加载失败，请稍后再试!");
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }


    public void UpdateSelectWarmPromptByType(String json, String title) {

        SelectWarmPromptByTypeBean bean;
        try {
            bean = new Gson().fromJson(json, SelectWarmPromptByTypeBean.class);
        } catch (Exception exception) {
            showConfirmAlert(mActivity, "提示", "数据解析错误");
            return;
        }

        if (!CommonUtil.checkState(mActivity, bean, json)) {
            return;
        }

        if (bean == null || bean.getData() == null || bean.getData().getContent() == null) {
            showConfirmAlert(mActivity, "提示", getString(R.string.no_data));
            return;
        }

        Intent mIntent = new Intent();
        mIntent.putExtra("urlStr", bean.getData().getContent());
        mIntent.putExtra("titleStr", title);
        mIntent.setClass(mActivity, SelectWarmPromptByTypeActivity.class);
        startActivity(mIntent);
    }

////////////////////////////////add 0817 根据银行卡查询对应的银行信息

    /**
     * 根据输入的银行卡号 查询 卡相关信息  卡bin
     */
    private void queryCardBinByBankAccountNo() {

        if (StringUtils.isNullOrEmpty(etRegisterStep1BankNumber.getText().toString())) {
            return;
        }

        Map<String, String> params = new HashMap<>();
        if (checkParam(params, "bankAccountNo", etRegisterStep1BankNumber.getText().toString(), "请输入银行卡号")) {
            return;
        }
        params.put("customerNo", "");
        OkGo.<String>post(HostConstant.QUERY_CARD_BIN_BY_BANK_ACCOUNT_NO)
                .tag(this)
                .upJson(new Gson().toJson(HttpUtils.getCommonParams(this, params)))
                .execute(new StringCallback() {
                    @Override
                    public void onSuccess(Response<String> response) {
                        parseJson_CardBinInfo(response.body());
                    }


                    @Override
                    public void onError(Response<String> response) {
                        super.onError(response);
                    }

                    @Override
                    public void onFinish() {
                        super.onFinish();
                    }
                });
    }

    /**
     * 解析鉴权申请接口返回的数据
     *
     * @param response
     */
    private void parseJson_CardBinInfo(String response) {
        SmartCardBinByBankAccountNoBean bean;
        try {
            bean = new Gson().fromJson(response, SmartCardBinByBankAccountNoBean.class);
        } catch (Exception exception) {
            showConfirmAlert(this, "提示", "数据解析错误");
            return;
        }

        if (bean == null
                || TextUtils.isEmpty(bean.getErrorCode())) {
            showToast(MentorConst.SERVER_BUSY_TIP);
            return;
        }
        BaseBean baseBean = new BaseBean();
        baseBean.setRespCode(bean.getErrorCode());
        baseBean.setRespMsg(bean.getErrorMessage());
        if (!CommonUtil.checkState(this, baseBean, response)) {
            return;
        }

        if (bean == null || bean.getData() == null || bean.getData().getCardBin() == null || StringUtils.isNullOrEmpty(bean.getData().getCardBin().getBankNo())) {
            showConfirmAlert(this, "提示", "暂不支持此卡");
            return;
        }

        if (bean.getData().getSupportBankMap() != null) {
            for (QueryBankInfoListBean.DataBean beanBank : bankList) {
                if (beanBank.getBankCode().equals(bean.getData().getSupportBankMap().getBankCode())) {
                    bankName = beanBank.getBankName();
                    tvRegisterStep1BankName.setText(bankName);
                    bankCode = beanBank.getBankCode();
                    trustChannelId = beanBank.getTrustChannelId();
                    currentCapitalMode = beanBank.getCapitalMode();
                    return;
                }
            }
        }
        showConfirmAlert(this, "提示", "暂不支持此卡");

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (requestCode == HostConstant.START_BANK_CARD && resultCode == HostConstant.RESULT_BANK_CARD) {
            isScanBankResult = true;
            cardNum = data.getStringExtra("CardNum").replace(" ", "");
            if (!TextUtils.isEmpty(cardNum)) {
                etRegisterStep1BankNumber.setText(cardNum);
                queryBankType();
                queryCardBinByBankAccountNo();
            }
        } else if (requestCode == HostConstant.START_CHANTS_BANK && resultCode == HostConstant.RESULT_CHANTS_BANK) {
            String status = data.getStringExtra("status");
            if ("Y".equals(status)) {
                gotoNextPage();
            }
        }
        super.onActivityResult(requestCode, resultCode, data);
    }
}
